package com.coder.config;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.annotation.Resource;

@Configuration
@EnableOpenApi
@Slf4j
public class Swagger3Config {

    @Value("${spring.profiles.active}")
    private String environment;
    @Resource
    private ApiInfo apiInfo;

    @Bean
    public Docket docket(){
        log.info("------------->{}<-------------", environment);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo)
                .enable(StrUtil.equals(environment, "dev"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.coder"))
                .build();
    }

    @Bean
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("404 Not Found 团队 Api文档")
                .version("1.0")
                .description("努力挣钱")
                .build();
    }
}
